package com.handinfo.android.uicontrols.controls;

import android.graphics.Bitmap;

import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.core.graphics.ITrans;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.utils.Tools;

/**
 * 标题控件
 * @author handinfo
 */
public class DWTitle extends DWControl
{

	private Bitmap img_side = null;
	private Bitmap img_middle = null;
//	private String m_text = null;
	private int m_color = Tools.WHITE;
	private DWFont m_font = DWFont.getDefaultFont();

	public DWTitle(String text, DWFrame frame)
	{
		setName(text);
		img_side = DWControlsManager.getInstance().createControlImage(DWControlsManager.RES_TITLE_SIDE);
		img_middle = DWControlsManager.getInstance().createControlImage(DWControlsManager.RES_TITLE_MIDDLE);
		setPoint(frame.m_show_x - 8, frame.m_show_y - 20);
		setShowWideHigh(frame.m_show_w + 16, img_middle.getHeight());
	}

	public void render(DWGraphics g)
	{
		drawTitle(g, m_show_x, m_show_y, m_show_w, m_show_h);
	}
	
	public void setFont(DWFont font) {
		m_font = font;
	}

	public final void drawTitle(DWGraphics g, int x, int y, int w, int h)
	{
		g.setClip(x, y, w, h);
		int midLen = w - (img_side.getWidth() << 1);
		if (midLen > 0) {
			int midAmount = midLen / img_middle.getWidth() + 1;
			for (int i = 0; i < midAmount; i++) {
				g.drawBitmap(img_middle, x + img_side.getWidth() + i * img_middle.getWidth(), y, Tools.LEFT_TOP);
			}
		}
		g.drawBitmap(img_side, x, y, Tools.LEFT_TOP);
		g.drawRegion(img_side, 0, 0, img_side.getWidth(), img_side.getHeight(), ITrans.TRANS_MIRROR, x + w, y, Tools.RIGHT_TOP);
		g.setClip(x, y, w, h);
		if (img_background != null) {
			g.drawBitmap(img_background, x + (w >> 1), y + (h >> 1), Tools.HCENTER_VCENTER);
		} else {
//			g.drawString(m_name == null ? "" : m_name, m_color, x + (w >> 1), y + ((h - m_font.getFontHeight()) / 2), Tools.HCENTER_TOP);
			g.drawShadowString(m_font, m_name == null ? "" : m_name, 
					DWControlsManager.COLOR_STROKE, m_color, x + (w >> 1), y + ((h - m_font.getFontHeight()) / 2), Tools.HCENTER_TOP);
		}
	}

	public void logic()
	{

	}

	public boolean doClick(float pointX, float pointY)
	{
		return false;
	}

	public void renderLimits(DWGraphics g)
	{

	}

}
